package com.adingxiong.cft.quartz;

import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;


/**
 * @ClassName AcceptConcurrentDemo
 * @Description  定时任务之并发
 * @Author xiongchao
 * @Date 2021/1/11 15:59
 **/
@Slf4j
public class AcceptConcurrentDemo {


    public static void main(String[] args) throws SchedulerException, InterruptedException {
        JobDetail detail = JobBuilder.newJob(AcceptConcurent.class)
                .withIdentity("job1","group1")
                .build();

        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger1")
                .usingJobData("name","zhangsan")
                .startNow()
                .build();

        Trigger trigger1 = TriggerBuilder.newTrigger()
                .withIdentity("trigger2")
                .usingJobData("name","wangwu")
                .startNow()
                .build();

        Scheduler scheduler = new StdSchedulerFactory().getScheduler();
        scheduler.scheduleJob(detail, Sets.newHashSet(trigger,trigger1),true);
        scheduler.start();

        Thread.sleep((2_100));
        scheduler.shutdown();



    }


    public static class AcceptConcurent implements Job {

        private String name ;

        public void setName(String name) {
            this.name = name;
        }

        @Override
        public void execute(JobExecutionContext context) throws JobExecutionException {
/*
            try {
                Thread.sleep(1_100);

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
*/

            log.info("my name is {}" ,name);

        }
    }

}
